package com.k.kc.util.tree.demo1;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author test
 */
public class Test {
    private static final ObjectMapper MAPPER = new ObjectMapper();
    public static void main(String[] args) {
        List<FunctionTreeDTO> currentTreeNodeList = new ArrayList<>();
        List<FunctionTreeDTO> allTreeNodeList = getSimpleTreeData();
        List<FunctionTreeDTO> treeList = TreeBuildUtil.buildTreeDTO(allTreeNodeList, currentTreeNodeList);
        System.out.println(treeList);
        try {
            System.out.println(MAPPER.writeValueAsString(treeList));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

    public static List<FunctionTreeDTO> getSimpleTreeData(){
        List<FunctionTreeDTO> z = new ArrayList<>();
        for(int i=0;i<5;i++){
            FunctionTreeDTO dto = new FunctionTreeDTO();
            dto.setCode(100+i +"");
            dto.setParentCode("1");
            dto.setFunctionName("name"+i);

            dto.setCurrentUnionKey(dto.getCode());
            dto.setParentUnionKey(dto.getParentCode());
            dto.setSort(1);
            z.add(dto);
        }
        FunctionTreeDTO dto1 = new FunctionTreeDTO();
        dto1.setCode(200+"");
        dto1.setParentCode("101");
        dto1.setFunctionName("name"+200);
        dto1.setCurrentUnionKey(dto1.getCode());
        dto1.setParentUnionKey(dto1.getParentCode());
        dto1.setSort(1);
        z.add(dto1);

        FunctionTreeDTO dto2 = new FunctionTreeDTO();
        dto2.setCode(300+"");
        dto2.setParentCode("200");
        dto2.setFunctionName("name"+300);
        dto2.setCurrentUnionKey(dto2.getCode());
        dto2.setParentUnionKey(dto2.getParentCode());
        dto2.setSort(1);
        z.add(dto2);

        FunctionTreeDTO dto3 = new FunctionTreeDTO();
        dto3.setCode(400+"");
        dto3.setParentCode("300");
        dto3.setFunctionName("name"+400);
        dto3.setCurrentUnionKey(dto3.getCode());
        dto3.setParentUnionKey(dto3.getParentCode());
        dto3.setSort(1);
        z.add(dto3);
        return z;
    }
}
